-- altar
-- created by panyl
-- 地牢格子：祭坛

return {
    restoreGrid = function(grid, info)
        if not info or not info.altar_info then
            return {};
        end

        local ret = {};
        local brief = info.altar_info;

        -- 服务器下发的数据，需要转换一下
        if info.altar_info.options.e then
            ret.altarType = brief.altar_type;
            ret.options = {};
            for _, option in pairs(brief.options) do
                if brief.altar_type == "gold" then
                    -- 金色祭坛
                    option.skillId = option.skill_id;
                    option.isNewSkill = option.is_new_skill;
                end

                table.insert(ret.options, option);
            end
            DungeonAltarM.updateAltarInfoByType(ret.altarType, ret);
        else
            -- 客户端自己生成的数据，无需转换
            ret = brief;
            DungeonAltarM.updateAltarInfoByType(ret.altarType, ret);
        end
    end,

    -- 收集上下文
    collectContext = function(grid)
        local ret = {};

        ret.altar_info = DungeonAltarM.queryAltarInfoByType(grid.altarType);

        return ret;
    end,

    autoFight = function(grid)
        return DungeonAltarM.doEvent(grid:getPos());
    end,
};
